package com.boot.config.result;

import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import com.baomidou.mybatisplus.extension.enums.ApiErrorCode;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * @Description:
 * @Author: HuangX
 * @Date: 2021/3/4
 */
@ApiModel("rest返回对象")
public class Model<T> {
    public static <T> Model<T> newSuccess(T data) {
        return new Model<T>().setData(data).setSuccess(true);
    }

    public static <T> Model<T> newSuccess(PageResult pagination, T data) {
        return new Model<T>().setData(data).setSuccess(true).setPagination(pagination);
    }

    public static <T> Model<T> newSuccess(T data ,Object ext){
        return new Model<T>().setData(data).setSuccess(true).setExt(ext);
    }

    public static <T> Model<T> newSuccess(PageResult pagination, T data, Object ext) {
        return new Model<T>().setData(data).setSuccess(true).setPagination(pagination).setExt(ext);
    }

    public static <T> Model<T> newFail(String msg) {
        return new Model<T>().setMsg(msg).setSuccess(false);
    }

    public static <T> Model<T> newFail(String msg, T data) {
        return new Model<T>().setSuccess(false).setMsg(msg).setData(data);
    }


    @ApiModelProperty(value = "业务是否成功")
    private boolean success = false;

    @ApiModelProperty(value = "消息提示")
    private String msg = "";

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @ApiModelProperty(value = "返回数据")
    private T data;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @ApiModelProperty(value = "分页属性")
    private PageResult pagination;

    private Object ext;

    public Object getExt() {
        return ext;
    }

    public Model<T> setExt(Object ext) {
        this.ext = ext;
        return this;
    }

    public boolean isSuccess() {
        return success;
    }

    public Model<T> setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Model<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public Model<T> setData(T data) {
        this.data = data;
        return this;
    }

    public PageResult getPagination() {
        return pagination;
    }

    public Model<T> setPagination(PageResult pagination) {
        this.pagination = pagination;
        return this;
    }
}
